Welcome back.
We're going to go ahead and wrap up the code for our starting menu.
So let's just go ahead and get started.
We're going back into our starting menu handler.
And where we left off was inside of our initialize function.
And we need to fill out the functionality for all of the different buttons that are inside of our GUI.
Basically, what we need to do here is we need to first get all of the servers that currently exist
in this particular lobby that we're in.
So we're going to get all of the current servers by using our server event, and we're going to invoke
the server with the action of.
To get a service.
We're just going to do get servers and it'll return back to us, all of the servers that currently exist
in the game, and we're going to loop through every single one of those servers in current servers.
And what we're going to do is we're just going to create a server frame for this particular server.
And that's all we need to do actually here for the initialize function, because the next section we
need to do is for starting this service.
And the reason why we're going to be connecting all of the functionality for the GUI buttons in this
function, rather than this function.
Is because I want to make sure that all of the event listeners on the server, on the client, have
all been set up from the initialize functions before we allow the player to actually start pressing
buttons within the GUI.
So we're going to do everything within the start function here for connecting functions to different
button events.
So the first button we need to listen to is our main server menu button.
And we're going to listen for when that's clicked.
And all we need to do is connect a function to this.
We're going to play the click sound.
So play click sound.
And since we're trying to go into the server menu, we need to set the visibility for the main frame
to be off or false.
And then the visibility for the server menu needs to be set to true.
The next button we need to listen to is our about button.
So when that is clicked.
Again, we need to play a quick sound.
We need to set the visibility of our main menu to false, and then set the about menu visibility.
To true.
The next button we need to listen to is our about back button.
So we'll do mouse button, one click.
We'll connect a function to that.
Again.
We'll play a click sound.
We'll set the about menu visible to false because again they're getting out of the about menu.
And we're going to set the visibility of the main menu back to true.
Next let's go ahead and start filling out the different functionality for the buttons in the server
menu.
So for example for the server join button, when that is clicked we need to connect a function here.
And we need to first verify that the player has actually selected a server.
So if they have not selected a server, then we're just going to return because we don't want to do
anything.
Otherwise we can play the click sound.
And then we're going to check whether or not the server has a password.
So if selected server get attribute.
Has password.
So if the server has a password, then we're going to set the server menu dot visible to false.
And we're going to set the enter password menu dot visibility to true because they need to enter a password
for this server.
Otherwise if the server doesn't have.
A, um, you know, password.
Then we can call our join server function.
And in fact, we haven't filled out this function yet, so let's go ahead and do that.
So inside of our join server function, what we need to do is we need to use our server event.
And we need to invoke the server that we wish to join a server.
So server action enums two server join server.
And we're going to pass to them the owner of the server that we wish to join.
So owner is equal to selected server get attribute owner.
And this should return back to us a boolean.
A message and then the server itself that we are attempting to join.
Because if you remember, when we wish to add a player to a server and player, let me look real quick.
Right?
Okay.
So when we add a player to a server, we're also going to be returning back to them.
The server object that this player joined.
So we're going to store that in that variable right there.
And if we were successful in joining the server then in server menu dot server name dot text.
Is going to be equal to the server dot owner dot name.
And we're going to concatenate it with apostrophe s server.
So whoever owns the server we're going to display their name inside of the server menu.
And then we're going to loop through every single player in server and ipairs server, dot players in
server.
And we're going to do is we're going to create a player frame for this player that is inside of the
server.
Then we can set the server menu dot visibility equal to false.
We're going to set the enter password menu dot visibility to false just in case it was open.
And then we're going to set the end server menu dot visibility equal to true.
Now inside of this for loop, it's actually going to create a player frame for every single player,
including us.
So if you don't want to have a frame of the local player itself, you could add an if statement here
to check to see if the player in the server is equal to the local player, and you would just continue
looping, but I'm just going to leave it like this.
That way we can see ourselves in the server as well, and then once that's done, we can go ahead and
display the message that is returned back from our invoke server function.
So it'll tell us if we successfully join the server, or it might give us an error message instead.
So let's go ahead and go back down to our start function, because the next button that we're going
to listen to is the create button.
So server create button mouse button one click.
We're going to connect a function to this.
We're going to play a click sound.
And then we're going to do server menu visibility equal to false.
And then we're going to enable the visibility of our create menu.
And then there's a back button in there as well.
So server back button dot mouse button one click connect a function to this.
We're going to set the server menu dot visibility equal to false, and then set the main menu dot visibility
equal to true.
And of course make sure to play a click sound.
Uh, the next section we could do is the buttons when you are inside of the server.
So in server, uh, leave button, which I believe is the only button.
When we click that, we're going to connect a function to it.
We're going to play the click sound.
And what we need to do is we need to invoke to the server to leave a server.
So local success message is going to be equal to server event invoke server.
We're going to pass the action server action enums dot two server dot leave server.
If we were not successful in leaving a server, then we're going to display a message of whatever the
error message is.
Otherwise.
What we could do is set in server menu dot visibility equal to false.
And then set server menu visibility equal to true.
And then we want to clear out the player list inside of our in server menu because we just left it.
So we're going to call our clear player list function.
And I guess that's the next one we can, um, fill out, because I don't believe we filled out this
function yet, so I'm actually going to pass the scrolling frame or the list of players we want to clear
out.
So in server menu dot player list we want to clear out this particular scrolling frame.
So let's go ahead and fill out this function.
So we'll get past a frame to this.
And what we could do is we could loop through every single other, you know, frame or aka text label
in eye pairs frame.
Actually, let me rename this.
We'll call this which frame.
So which frame?
We want to clear out the player list for?
Where we're going to do is we're going to check if this frame in here is a text button which only belongs
to, you know, those different players.
If it is a text button then we're just going to destroy the frame.
And then we're also going to make sure to set selected player.
Equal.
To nil.
Cool.
Seems good.
Now let's go ahead and start filling out the buttons for when we are the owner of a server.
So in owner menu.
Uh, let's do the remove player button.
So when we click that, what we're going to do is check if we have a selected player.
So if we do not have a selected player selected player then we're just going to return because we don't
care.
Otherwise we're going to play the click sound.
And then we're going to request to the server to remove a player.
So success message is going to be equal to the server event.
We're going to invoke to the server with the action of.
Remove player and the player we wish to remove.
Uh, we'll just call it player to remove because I believe that is the key value pair we use.
So player to remove.
Yeah.
So that's the key value pair.
We need to fulfill the player to remove key value pair.
So the player to remove is going to be equal to selected player.
And we're going to get the attribute on this text button of owner.
So we're passing the name to the server of the player we wish to remove.
And then once that is done, we can go ahead and display a message based on what is ever returned from
our remote function.
All right.
The next button we need to listen to is the in owner delete button.
Let's say the owner wants to delete the server.
So we're going to listen for when that is clicked.
And what we're going to do here is we're going to play a quick sound.
And we're going to again invoke to the server.
So server event invoke server with the action of two server dot destroy or delete server.
And then if we are successful then what we could do is we could set currently owning server equal to
false.
We're going to set in owner menu dot visibility equal to false.
And then server menu dot visibility is going to be set to true.
And we're also going to clear out the player list inside of the inn owner menu player list.
And then at the very end, we can go ahead and display the message that gets returned from our remote
function.
Another button we need to listen to is the end owner start button.
So when that is clicked, we'll connect a function to this as well.
We'll play the click sound.
And what we could do here is we could use our server event and invoke to the server that we wish to
start the game.
So server.
Action.
Enums dot two server.
Dot start game or start server.
We'll get the success.
And potential message from this if there is one.
And actually, I'm not worried about a message from this because we're just going to be starting the
server.
Okay.
The next buttons we need to listen to is when we want to create a server.
So when we are in the create menu.
So create button dot mouse button click we're going to connect a function to this.
We're going to play the click sound.
And this is when we've fulfilled all of the settings.
And we need to go ahead and tell the server that we want to, you know, create our own custom server.
So I'm going to create a table called data.
And here it's going to store whether or not the server has a password.
So we'll set that equal to is password on.
We'll store the password in here as well.
So password input menu dot text box dot text.
And then max size, we're going to set using a function called two number.
And we're going to convert inside of our server size menu.
We're going to get the number text label and get the text in there, and we're going to convert that
to a number to represent the max size.
And we're going to use our server event to invoke to the server.
That we wish to create a server.
So create server and then we're going to pass this data.
And we're going to store the success and then the message from the server.
So if we were successful in creating a server, then we're going to set currently owning server equal
to true.
We're going to set the create menu dot visibility equal to false.
And then we're going to enable in our menu that visible equal to true.
And then we're going to display a message of whatever is returned from our server event.
So let me go ahead and verify that the data we're passing here is correct.
So if we go to our server service when we wish to create a server.
Yeah.
We're going to have the password.
Or the boolean of whether or not we have a password, the password itself, as well as the max size
for the server.
Okay.
Looks good.
The next button we can listen to is the Create Cancel button.
So when we are in the create menu, if we don't want to create a server, we change our mind.
Then we're going to play a click sound.
We're going to set create menu dot visibility equal to false.
And then we're going to set the server menu dot visibility equal to true.
And then we need to listen to that toggle button for the password.
So we'll call it create.
Password toggle button will listen for when that is clicked.
So when that is clicked, we're going to play the click sound.
And we're going to check if password is on.
So if is password on then we're going to say is password on.
Back to false.
So let's say you know they toggle it back off.
We're going to set password toggle menu.
And we're going to set the fill in there.
The visibility of that to false.
And then we're going to set the password input menu dot visibility to false as well.
So if we go to our create server menu.
So let me enable the visibility here.
Disable the visibility of this one.
So when we click this here.
Um, let's go ahead and find it.
It is.
Yeah.
This password toggle here.
There's a fill in here.
So when that's enabled.
It'll fill in.
You know this to show that we have enabled the password.
And then it'll go ahead and put in that password input down here.
And then if we toggle it back off, it'll make this disappear and turn the fill back off.
If the password has not been turned on, then we're going to set its password on to true.
Set password toggle menu dot fill dot visible equal to true and then password input menu dot visibility
equal to true as well.
Okay.
The next button we need to listen to is the create server.
Um, I believe it is the size or what is it?
It's create.
We find it increase.
Yeah.
So let's do or let's do the decrease button first.
So when that is clicked we're going to connect a function to that.
We're going to play the click sound.
We're going to create a variable I'm going to call it uh new number.
So this is the new number we want to set the server size to.
So we're going to do two number server size menu dot number dot text.
So we get that as a number.
And then we're going to subtract it by one because we're decreasing it here.
If this new number is less than the minimum server size then new number is going to be equal to min
server size.
And we're going to set server size menu dot number dot text equal to this new number.
Now, if you don't want to use an if statement here, you could also use Math.max.
So we could set new num equal to math dot max and pass new num and then minimum server size.
So let's say they somehow make new numbers zero.
Minimum server size is one.
So that's the greater number out of these two numbers.
So it'll return one back to Newnham.
And we'll set that as the number inside of this text label.
And then we could do the same thing for the increase button.
So create increase button mouse button one.
Click connect a function.
Play a click sound local new number is going to be equal to two string server size menu dot number dot
text subtract it.
Or actually we're going to add one.
And then we can set new num equal to math dot minimum.
So we're going to pass a new num.
And then max server size.
So if they accidentally go above the max server size, this will be the smaller number out of the two.
And we'll set new num to that.
And then we can set server size menu dot number dot text equal to new num.
All right.
We're almost done here.
We need to listen to that okay button in our message menu.
So message menu okay.
Button when that is clicked.
You need to apply the click sound, and then we can just set the message menu dot visibility equal to
false.
And then, uh, we can lastly, listen to our, um, password input menu.
So let me disable visibility here.
So when this menu is in here we have two buttons we need to listen to.
So enter password.
Uh let's first listen to the submit button.
So when that is clicked.
Uh, we need to invoke to the server using our server event that we want to submit a password.
So server action enums dot two server dot submit password.
And the owner of the server we wish to submit this password to is going to be owner is equal to selected
server.
Get attribute owner.
And then what was the other key value pair we needed to do so if we had submit password.
Right.
We have our owner and then.
Ah, yes, we need to fulfill a key value pair of submitted password so we can set submitted password.
Equal two.
Enter password menu dot textbox dot text.
We also need to play the click sound for when that is clicked, and then we can get the success and
then the message from the server.
If we were successful, then we can go ahead and join this server because we are now, or we should
be within the whitelist of this particular server.
And then we're just going to display a message of whatever is returned from the server.
The last button we need to fill out for I believe is the enter password menu back button.
So when we click that bad boy again, we need to play a click sound.
We need to set the enter password menu visibility equal to false, and then set the server menu visibility
equal to true.
And you know what?
I think that is all.
So we've gotten all of the stuff filled out.
You know what?
Let's actually do a quick test.
Why not?
So let's go ahead and put this, uh, starting menu back to its default.
So I believe only the main frame is visible.
And we can go ahead and go to the test and hit play.
Any errors we should see show up inside of the console.
So let's go ahead and see.
So we did load the server service.
That's good.
And we initialized it.
Very good.
If we look on the client here, if we load.
Yep.
Looks like we initialize the starting menu.
That's awesome.
Oh, it looks like we forgot to get rid of that print statement within our camera manipulation.
We'll fix that later.
But anyways, now that we're inside of the server menu, we should be able to click the about button.
We got a click.
We can hit back.
Boom, we're back here.
We can go ahead and hit servers.
We are in the server menu.
We can go ahead and hit back as well.
So let's go ahead and create a server.
Perfect.
That's worked.
Can we increase.
Yes we can.
All right.
We're constrained between 1 and 10.
Can I enable a password?
Yep.
And then I can type in a password here like hello.
And then we can hit create server.
There we go.
We got a message server created.
We can hit okay.
And that closes out.
And now we are inside of our server.
We can delete the server.
The server was deleted, but it looks like we did get an error.
So invalid argument number one to Ipairs table expected got instance.
So.
Oh gosh, this is printing like crazy.
So let me go ahead and try to get to it.
Okay, let me get.
Let me go.
Here.
Okay, so where is our error at?
Invalid argument to Ipairs table.
Expected got instance.
Oh, okay.
We forgot to use a getchildren here within our starting menu handler, so let's fix that.
Let's we'll save those changes.
So inside of our clear players function.
We need to make sure to put get children here instead of passing the instance itself.
And actually let me go back to our camera manipulation handler.
And let me find that little goofy print statement here.
It is going to get rid of that bad boy.
No more of that.
We don't need it.
And let's go ahead and test this out again.
All right.
Create a server.
Enter a password, blah blah blah.
Hit create server created.
That's good.
Can we delete it?
Yes we can.
Server deleted.
There is nothing in our server menu and so far actually everything's looking good.
So if I hit start game perfect our teleporting menu shows up.
And of course we're going to get this Http 403 forbidden error in here because we're not allowed to
use the teleport service while we're in studio, but at least we know that's working, so that's nice.
So to actually get this fully tested out here, we're going to launch a local server with three players
here.
Okay, here we are with our three player server.
So what I'm going to do is we're going to check to make sure that a server actually appears within the
uh, within our server menu.
So if I create a server here and let's say I make the size like three, if I hit create, we get server
created.
And then as you can see over here, we get our server added to our other clients.
And of course we can select this server.
We get a red highlight over it and we're allowed to join the server.
So if I hit join it'll tell us we have joined the server.
And as you can see it updated the player count over here as well.
And now we can see both of our players are in here.
And I can see the other player that is inside of my server.
And I can select this player and I can remove them.
So it says player removed and it will tell them you have been kicked from the server.
And it updated the player count as well.
But I can go ahead and join back.
I can remove this player again.
As you can see, it's updating the color.
Now if I keep this server selected and I go and delete the server, there we go.
Our buttons get grayed out.
Very nice.
Let me go ahead and create a server with a password.
So I'll just do 1234 create.
Now if I try to join the server we're going to get into the enter password menu.
And I can type in some password like hello.
If I hit submit it'll tell me password was incorrect.
But I can go ahead and type something in like one, two three, four and hit submit and it'll get success.
And now we are inside of the server player one server and they showed up here as well.
And if I go ahead and hit remove player player removed try to join the server again.
I can type in whatever I want, but password was incorrect.
I'll have to resubmit the password.
And now I'm back inside of the server.
And if I hit start game, GUI gets faded out for those two players.
Very cool.
But it doesn't get faded out on this guy over here.
If I try to join the server and I enter in the correct password.
Actually, we are getting a success message.
That is interesting.
So when the server is locked.
Instead, we should tell this player that you know, the server locked.
Oh, hey, at least our teleport timeout works, so that's neat too.
So let's go ahead and make a change to that as well.
Let's see here we're invoking to the server to join a server.
Let's go to the server service and look for join server.
Here we are.
So we'll get success and result from server to join ad player.
So if we go to our ad player function.
Try to find it here.
Here we go.
It should be returning.
Server is locked.
Oh, you know what?
We forgot to call our, um, lock and unlock function on a particular server.
So when we want to start the game, we need to actually lock the server.
So we're going to do, uh, self lock.
That's why it wasn't showing the correct message.
Otherwise.
That is our server menu basically complete.
All we need to do now is fill out the other services on the server and the client.
So I'll go ahead and see in the next lectures.